<script type="text/javascript">
<!--
var pid = "";
var process = canvas.process;

$(function(){
    $('#process-properties-accordion').accordion({
		onSelect:function(title,index){
				if(title=='Variables'){
					var pp = $('#process-properties-accordion').accordion('getSelected');
					if (pp){
    					pp.panel('refresh','processVariable.html');
					}
				}
				if(title=='Data Objects'){
					var pp = $('#process-properties-accordion').accordion('getSelected');
					if (pp){
    					pp.panel('refresh','processDataObject.html');
					}
				}
			}
	});
	_listener_win = $('#listener-win').window({
		//href:'${ctx}/wf/procdef/procdef!forTaskListenerConfig.action',   
	    closed:true,
	    //cache:false,
	    draggable:false,
	    collapsible:false,
	    minimizable:false,
	    maximizable:false,
	    modal:true,
	    shadow:true
	});
	$('#process-listeners-list').datagrid({
		//title:"Listener",
		//url:'${ctx}/wf/procdef/procdef!search.action',//加载表格数据的URL
		singleSelect:true,
		//width:500,
		height:300,
		//idField:'id',
		//pagination:true,
		//pageSize:15,
		//pageNumber:1,
		//pageList:[10,15],
		rownumbers:true,
		//sortName:'id',
	    //sortOrder:'asc',
	    striped:true,
	    toolbar:[{
	        text:'New',
	        iconCls:'icon-add',
	        handler:function(){
	    		_listener_win.window('open');
	    		//_listener_frame.src="";
	    		_listener_win.window('refresh','processListenerConfig.html');
	    		//alert(_listener_frame.document.body.innerHTML);
	        }
	    }]
	});
	
	populateProcessProperites();
});
function listenerActionBt(value,rowData,rowIndex){
	var id = rowData.id;
	var e = '<img onclick="editListener(\''+id+'\')" src="image/edit.gif" title="'+"修改"+'" style="cursor:hand;"/>';   
    var d = '<img onclick="deleteListener(\''+id+'\')" src="image/delete.gif" title="'+"删除"+'" style="cursor:hand;"/>';
	return e+'&nbsp;'+d;
}
function editListener(id){
	_listener_win.window('open');
	_listener_win.window('refresh','processListenerConfig.html');
}
function deleteListener(id){
	process.deleteListener(id);
	loadTaskListeners();
}
function saveProcessProperties(){
	process.id=$('#id').val();
	process.name=$('#name').val();
	process.category=$('#category').val();
	process.documentation=$('#documentation').val();
	$.messager.alert('Info','保存成功！','info');
}
function populateProcessProperites(){
	$('#id').val(process.id);
	$('#name').val(process.name);
	$('#category').val(process.category);
	$('#documentation').val(process.documentation);
	loadProcessListeners();
}
function loadProcessListeners(){
	var listeners = process.listeners;
	var listener_grid_rows=[];
	//alert(listeners.getSize());
	for(var i=0;i<listeners.getSize();i++){
		var listener = listeners.get(i);
		var nlistener = {
					id:listener.getId(),
					listenerImplimentation:listener.getServiceImplementation(),
					type:listener.serviceType,
					event:listener.event,
					fields:listener.getFieldsString(),
					action:''
				};
		listener_grid_rows[i]=nlistener;
	};
	//alert(listener_grid_rows);
	var listener_grid_data={
			total:listeners.getSize(),
			rows:listener_grid_rows
	};
	$('#process-listeners-list').datagrid('loadData',listener_grid_data);
}
//-->
</script>
<div id="process-properties-layout" class="easyui-layout" fit="true">
	<div id="task-properties-toolbar-panel" region="north" border="false" style="height:30px;background:#E1F0F2;">
		<a href="##" id="sb2" class="easyui-linkbutton" plain="true" iconCls="icon-save" onclick="saveProcessProperties()">Save</a>
	</div>
	<div id="process-properties-panel" region="center" border="true">
		<div id="process-properties-accordion" class="easyui-accordion" fit="true" border="false">
			<div id="general" title="General" selected="true" class="properties-menu">
				<table id="general-properties">
					<tr>
						<td align="right">Id:</td>
						<td><input type="text" id="id" name="id" size="50" value=""/></td>
					</tr>
					<tr>
						<td align="right">Name:</td>
						<td><input type="text" id="name" name="name" size="50" value=""/></td>
					</tr>
					<tr>
						<td align="right">Category:</td>
						<td><input type="text" id="category" name="category" size="50" value=""/></td>
					</tr>
					<tr>
						<td align="right">Documentation:</td>
						<td><textarea id="documentation" name="documentation" cols="20" rows="5"></textarea></td>
					</tr>
				</table>
			</div>
			<div id="variables" title="Variables" class="properties-menu">
				
			</div>
			<div id="dataObjects" title="Data Objects" class="properties-menu">
				
			</div>
			<div id="listeners" title="Listeners" style="overflow: hidden;">
				<table id="process-listeners-list">
					<thead>
					<tr>
					<th field="listenerImplimentation" width="200" align="middle" sortable="false">Listener Implimentation</th>
					<th field="type" width="70" align="middle" sortable="false">Type</th>
					<th field="event" width="70" align="middle" sortable="false">Event</th>
					<th field="fields" width="100" align="middle" >Fields</th>
					<th field="action" width="100" align="middle" formatter="listenerActionBt">Action</th>
					</tr>
					</thead>
				</table>
			</div>
		</div>
	</div>
</div>